/*
 * -------------------------------------------------------------------------------
 * Additional information for A078707 and A243520 (By: R. J. Cano, Jun 17 2014)
 * -------------------------------------------------------------------------------
 * (URL: http://oeis.org/w/images/5/5d/AdditionalInformationA078707andA243520.txt)
 * 
 * Dear user: This file is also a PARI-GP script.
 * The present content is subject to: The OEIS End-User License Agreement
 * (Visit http://oeis.org/wiki/The_OEIS_End-User_License_Agreement)
 * 
 * Specifically for A078707, see note #3.
 * 
 */

/* The base for a class of additive recurrence relations. */
f0(n,v,i)=if(!n,i,f0(n-1,v,i)+v[1+n%2]);

/* Multiplicative analogue for f0() */
g0(n,v,i)=if(!n,i,g0(n-1,v,i)*v[1+n%2]);

/* It can be verified that ceil((x+1)/2) is identical to h(x) as defined below: */
h(x)=(x+(x%2))\2+!(x%2-!x)+!x;

/* By defining the following such that: even(x)+odd(x) == x+1 */
even(x)=ceil((x+1)/2);
odd(x)={my(z=even(x));x-z+1};
/*                   
 * Note 1. ...Therefore even(x) might be defined alternatively as even(x)=h(x);
 * 
 *         (It means of course: By replacing here the corresponding right-hand sides)
 */

/* An iterative version of f0 indeed is */
f1(x,v,i)={my(c=min(v[1],v[2]),w);w=vector(#v,j,v[j]-c);i+x*c+(even(x)-1)*w[1]+odd(x)*w[2]}

/* Now a possible iterative version "everything built-in" (**APPARENTLY an optimization) would be: */
f2(x,v,i)={my(c=min(v[1],v[2]),z=ceil((x+1)/2),w);w=vector(#v,j,v[j]-c);i+x*c+(z-1)*w[1]+(x-z+1)*w[2]}
/*                   
 * Note 2. f2() seems not much significant for A243520 since there
 *         are available other alternatives. However the knowledge
 *         about how to avoid the recursion in f0() might be 
 *         (appreciably) useful in general.
 */

/*
 * Note 3. g0(n,[1,n],1) is the same than A078707(n)
 * 
 *         Notice however it recalls the factorial of n.
 *         indeed, it was named initially by the author of this sourcecode:
 * 
 *         "The ceiling factorial" of n
 * 
 *         Due the similarity of the call:
 * 
 *                g0(n,[1,n],1)
 * 
 *         with:
 * 
 *                f0(n,[0,1],0)
 * 
 *         In the sense of being both based upon the corresponding
 *         neutral elements of their underlying operations.
 * 
 *         In fact there might exist at least three different ways of
 *         defining these objects, here they will be named respectively:
 * 
 *         "The ceiling factorial of the zeroth kind",
 * 
 *                 G0(n)= if(!n,1,g0(n-1,[1,n],1)*[1,n][1+n%2]);
 * 
 *                       ...which in fact actually is a power (A078707).
 * 
 *         "The ceiling factorial of the first kind",
 *
 *                 G1(n)= if(!n,1,(g0(n-1,[1,n-1],1)+!n)*[1,n][1+n%2]);
 * 
 *         "The ceiling factorial of the second kind",
 *
 *                 G2(n)= if(!n,1,(g0(n-1,[n-1,1],1)+!n)*[n,1][1+n%2]);
 * 
 */

 G0(n)= if(!n,1,g0(n-1,[1,n],1)*[1,n][1+n%2]);
 G1(n)= if(!n,1,(g0(n-1,[1,n-1],1)+!n)*[1,n][1+n%2]);
 G2(n)= if(!n,1,(g0(n-1,[n-1,1],1)+!n)*[n,1][1+n%2]);

/* Now: An alternative def. for ceil(n/2) */
ceil2(x)=f2(x,[0,1],0);

/* Five alternative studied ways of getting A243520(n) */
a243520_0(n)=-5/4*(-1)^n+11*n/2+5/4;
a243520_1(n)=5*n+2*(n%2)+ceil(n/2);
a243520_2(n)=f0(n,[3,8],0);
a243520_3(n)=f1(n,[3,8],0);
a243520_4(n)=f2(n,[3,8],0);

/* And finally for the "ceiling factorial":
 * 
 * A bonus routine: s=0 for a b-file, s=1 for a search field, both with u terms.
 * 
 */
bfileprinter(u,s=0)=for(k=0,u,if(s,print1(","G0(k)),print(k" "G0(k))));